package com.wang.event;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.function.Consumer;

public class EventManager<T> {
    private List<Consumer<Event<T>>> consumerList = new ArrayList<>();
    private Executor executor;

    public EventManager(Executor executor) {
        this.executor = executor;
    }

    public void register(Consumer<Event<T>> consumer) {
        consumerList.add(consumer);
    }

    public void sendEvent(Event<T> event) {
         for (Consumer<Event<T>> eventConsumer : consumerList) {
            this.executor.execute(() -> {
                eventConsumer.accept(event);
            });
        }
    }
}
